package cn.tedu.spring.di;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

@Repository
@PropertySource("classpath:application.properties")    //PropertySource注解引入外部属性文件，通常在resources目录下
public class UserDao {
    //@Value("")  基本类型依赖注入的注解，比如字符串类型，整形，浮点型...可以添加在属性上，也可以添加在set()方法上
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;
    //位置2：可以添加在set方法上
//    @Value("root")
    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "UserDao{" +
                "url='" + url + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
